package com.youxin.cpcenter.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.youxin.busfoundation.bean.ResponseObject;
import com.youxin.busfoundation.bean.delegate.RequestDelegateBean;
import com.youxin.busfoundation.bean.sms.RequestSmsBean;
import com.youxin.cpcenter.common.log.LogMethod;
import com.youxin.cpcenter.service.DelegateService;
import com.youxin.foundation.utils.ObjectUtils;
import com.youxin.foundation.utils.RegexUtils;

/**
 * 委托接口实现
 * @author yingde.cao
 *
 */
@RestController
public class DelegateController extends BaseController{
	@Autowired
	private DelegateService delegateService;
	
	/**
	 * 短信联系企业联系人
	 * @param request
	 * @param httpServletResponse
	 * @param requestBean
	 * @return
	 */
	@LogMethod(id="ent.delegate.send",eventContent={})
	@RequestMapping(value = "/api/delegate/send", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject sendDelegate(HttpServletRequest request, HttpServletResponse httpServletResponse,
			@RequestBody RequestDelegateBean requestBean) {
		try {	
			ObjectUtils.requestNonNull(requestBean,"参数不能为空,格式为JSON.");
			ObjectUtils.requestNonEmpty(requestBean.getMessage(), "信息不能为空");
			return delegateService.sendMessage(requestBean);
		} catch (Exception e) {		
			logger.error("/api/delegate/send", e);
			return ResponseObject.systemError(e);
		}
	}
	
	@LogMethod(id="ent.delegate.empty",eventContent={})
	@RequestMapping(value = "/test", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject test(HttpServletRequest request, HttpServletResponse httpServletResponse,
			@RequestBody RequestDelegateBean requestBean) {
		return new ResponseObject();
	}
	
}
